package org.xbill.DNS.tests;

import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Name;
import org.xbill.DNS.Record;
import org.xbill.DNS.TSIG;
import org.xbill.DNS.ZoneTransferIn;
import org.xbill.DNS.ZoneTransferIn.Delta;

public class xfrin
{
  public static void main(String[] paramArrayOfString)
    throws Exception
  {
    Name localName;
    ZoneTransferIn localZoneTransferIn;
    List localList;
    Iterator localIterator4;
    TSIG localTSIG = null;
    String str1 = null;
    int i = 53;
    boolean bool = false;
    int j = 0;
    int k = -1;
    if (j >= paramArrayOfString.length)
    {
      if (j >= paramArrayOfString.length)
        usage("no zone name specified");
      localName = Name.fromString(paramArrayOfString[j]);
      if (str1 == null)
      {
        Lookup localLookup = new Lookup(localName, 2);
        Record[] arrayOfRecord = localLookup.run();
        if (arrayOfRecord == null)
        {
          System.out.println("failed to look up NS record: " + localLookup.getErrorString());
          System.exit(1);
        }
        str1 = arrayOfRecord[0].rdataToString();
        System.out.println("sending to server '" + str1 + "'");
      }
      if (k < 0)
        break label440;
      localZoneTransferIn = ZoneTransferIn.newIXFR(localName, k, bool, str1, i, localTSIG);
      localList = localZoneTransferIn.run();
      if (!(localZoneTransferIn.isAXFR()))
        break label480;
      if (k < 0)
        break label453;
      System.out.println("AXFR-like IXFR response");
      localIterator4 = localList.iterator();
      if (localIterator4.hasNext())
        break label464;
    }
    while (true)
    {
      do
      {
        label433: label440: label453: label464: label480: Iterator localIterator1;
        do
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                int l;
                return;
                if (paramArrayOfString[j].equals("-i"))
                {
                  l = Integer.parseInt(paramArrayOfString[(++j)]);
                  if (l < 0)
                    usage("invalid serial number");
                }
                while (true)
                {
                  do
                    while (true)
                    {
                      while (true)
                      {
                        while (true)
                        {
                          while (true)
                          {
                            while (true)
                            {
                              ++j;
                              k = l;
                            }
                            if (!(paramArrayOfString[j].equals("-k")))
                              break;
                            String str2 = paramArrayOfString[(++j)];
                            int i1 = str2.indexOf(47);
                            if (i1 < 0)
                              usage("invalid key");
                            localTSIG = new TSIG(str2.substring(0, i1), str2.substring(i1 + 1));
                            l = k;
                          }
                          if (!(paramArrayOfString[j].equals("-s")))
                            break;
                          str1 = paramArrayOfString[(++j)];
                          l = k;
                        }
                        if (!(paramArrayOfString[j].equals("-p")))
                          break;
                        i = Integer.parseInt(paramArrayOfString[(++j)]);
                        if ((i >= 0) && (i <= 65535))
                          break label433;
                        usage("invalid port");
                        l = k;
                      }
                      if (!(paramArrayOfString[j].equals("-f")))
                        break;
                      bool = true;
                      l = k;
                    }
                  while (!(paramArrayOfString[j].startsWith("-")));
                  usage("invalid option");
                  l = k;
                }
                localZoneTransferIn = ZoneTransferIn.newAXFR(localName, str1, i, localTSIG);
              }
              System.out.println("AXFR response");
            }
            System.out.println(localIterator4.next());
          }
          if (!(localZoneTransferIn.isIXFR()))
            break label658;
          System.out.println("IXFR response");
          localIterator1 = localList.iterator();
        }
        while (!(localIterator1.hasNext()));
        ZoneTransferIn.Delta localDelta = (ZoneTransferIn.Delta)localIterator1.next();
        System.out.println("delta from " + localDelta.start + " to " + localDelta.end);
        System.out.println("deletes");
        Iterator localIterator2 = localDelta.deletes.iterator();
        while (true)
        {
          if (!(localIterator2.hasNext()))
          {
            System.out.println("adds");
            Iterator localIterator3 = localDelta.adds.iterator();
            while (true)
            {
              if (!(localIterator3.hasNext()));
              System.out.println(localIterator3.next());
            }
          }
          label658: System.out.println(localIterator2.next());
        }
      }
      while (!(localZoneTransferIn.isCurrent()));
      System.out.println("up to date");
    }
  }

  private static void usage(String paramString)
  {
    System.out.println("Error: " + paramString);
    System.out.println("usage: xfrin [-i serial] [-k keyname/secret] [-s server] [-p port] [-f] zone");
    System.exit(1);
  }
}